<?php
require_once FOREGROUND_COMMON_ACTION_SERVICE_DIR . '/default.php';

class foreground_order_list_action_service extends foreground_default_common_action_service
{
    protected static $_instance;

    public static function get_instance()
    {
        if (null === self::$_instance) {
            self::$_instance = new self();
        }

        return self::$_instance;
    }


    protected function _current_page_process()
    {
        //var_dump(__METHOD__); exit();
        
        $request_data = $_GET;
        
        //$page_num = 1;
        $page_num = init_user_data_key($request_data, 'page_num', 'int');
        //var_dump($page_num); exit();
        $item_count = 5;
        //$item_count = init_user_data_key($request_data, 'item_count', 'int');
        //var_dump($item_count); exit();
        $page_range = 5;
        //$page_range = init_user_data_key($request_data, 'page_range', 'int');
        //var_dump($page_range); exit();
    
        $action_data = wwy_action::$data;
	    $session_member_info = $action_data['session_member_info'];
        $member_id = $session_member_info['id'];
        
        $where = array('member_id' => $member_id);
        //sn编号
        $order_sn = init_user_data_key($request_data, 'order_sn', 'str', '');
        self::add_view_data('order_sn', $order_sn);
        if($order_sn !== ''){
            $where['order_sn'] = $order_sn;
        }
        //状态：10为全部
        $status = init_user_data_key($request_data, 'status', 'int', 10);
        if(!in_array($status, array(10, 0, 1, 2, 3, -2))){
            $status = 10;
        }
        self::add_view_data('status', $status);
        if($status !== 10){
            $where['status'] = $status;
        }
    
        $model_foreground_order = wwy_resource_container::get_model_foreground_order();
        //$where     = array('member_id' => $member_id);
        $order     = array('id Desc');
        $options   = array('page_num' => $page_num, 'item_count' => $item_count, 'page_range' => $page_range);
        $list      = $model_foreground_order->get_list($where, $order, $options);
        //var_dump($list); exit();
        self::add_view_data('order_list', $list['list']);
        self::add_view_data('page_data', $list['page_data']);
        
        $list['good'] = array();
        $model_foreground_order_good = wwy_resource_container::get_model_foreground_order_good();
        foreach ($list['list'] as $order_item) {
            $order_id = $order_item['id'];
            $good_where = array('order_id' => $order_id);
            $order_good_list = $model_foreground_order_good->fetch_all($good_where);
            //var_dump($order_good_list); exit();
            $list['good'][$order_id] = $order_good_list;
        }
        //print_r($list['good']); exit();
        self::add_view_data('order_list_good', $list['good']);
    
        //SEO:title,keywords,description
        self::add_view_data('page_title', '订单列表');
    }
}